#!/usr/bin/python
# coding=utf8
#
# Copyright (C) 2011 XNData contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys, os
sys.path.append (os.getcwd () + '/../../')
import xndata.client
import xndata.client.status
import unittest
import datetime

class XNStatusClientTestCase (unittest.TestCase):

    def setUp (self):
        self.client = xndata.client.status.XNStatusClient (uname="zhangchitc@gmail.com", upass="aaaaaaaa")


    def testPassLogin (self):
        client = xndata.client.status.XNStatusClient (uname="zhangchitc@gmail.com", upass="aaaaaaaa")
        self.assertEqual (client.user_id, "242124580")
        self.assertEqual (client.user_name, "张弛")

    def testClientLogin (self):
        client = xndata.client.XNClient ("zhangchitc@gmail.com", "aaaaaaaa")
        pClient = xndata.client.status.XNStatusClient (xnclient=client)
        self.assertEqual (pClient.user_id, "242124580")
        self.assertEqual (pClient.user_name, "张弛")


    def test_get_total_status (self):
        # Ren su yi's status
        self.assertTrue ( self.client.getTotalStatus ("247780420") >= 407)
        # My status
        self.assertTrue (self.client.getTotalStatus ("242124580") >= 886)

    def test_get_total_status_list (self):
        # Ren su yi's status
        self.assertTrue ( self.client.getTotalStatusList ("247780420") >= 21)
        # My status
        self.assertTrue (self.client.getTotalStatusList ("242124580") >= 45)

    def test_get_all_status (self):
        # Ren su yi's status
        slist = self.client.getAllStatus ("247780420")
        last = len (slist) - 1
        self.assertEqual (slist[last].status_id, "134493132")
        self.assertEqual (slist[last].content, "下雨啦 嗯嗯 看打雷真有趣")
        self.assertEqual (slist[last].author_id, "247780420")
        self.assertEqual (slist[last].author_name, "任素仪Silvia")
        self.assertEqual (slist[last].pub_time, datetime.datetime (2008, 7, 12, 18, 58, 0))
        
        # My status
        slist = self.client.getAllStatus ("242124580")
        last = len (slist) - 1
        self.assertEqual (slist[last].status_id, "65115434")
        self.assertEqual (slist[last].content, "宅家ing")
        self.assertEqual (slist[last].author_id, "242124580")
        self.assertEqual (slist[last].author_name, "张弛")
        self.assertEqual (slist[last].pub_time, datetime.datetime (2008, 3, 21, 2, 35, 0))



suite1 = unittest.TestLoader().loadTestsFromTestCase (XNStatusClientTestCase)
allsuite = unittest.TestSuite ([suite1])

unittest.TextTestRunner(verbosity=2).run(allsuite)

